package com.sys.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.sys.bean.Admin;
import com.sys.exception.SysException;
import com.sys.mapper.AdminMapper;
import com.sys.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin login(String username, String password) throws SysException {
        Admin admin = adminMapper.selectByUsername(username);
        if (admin == null){
            throw new SysException("用户名错误,请确认后重新登录");
        }
        //对浏览器中输入的密码进行两次加密-md5
        String md5Pwd = SecureUtil.md5(SecureUtil.md5(password));
        if (!md5Pwd.equals(admin.getPassword())) {
            throw new SysException("密码错误,请确认后重新登录");
        }
        return admin;

    }

    @Override
    public List<Map<String, Object>> selectTop5ParkNameAndCount() {
        return adminMapper.selectTop5ParkNameAndCount();
    }

    @Override
    public Admin selectByid(Integer id) {
        return adminMapper.selectByid(id);
    }
}
